public class MyQueue {
    //用单链表实现队列
    static class ListNode{
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    private int usedSize;

    public int getUsedSize() {
        return usedSize;
    }
    public void offer(int val){
        ListNode node = new ListNode(val);
        //使用尾插法入队列
        if (head == null){
            head = node;
            last = node;
        }
        last.next = node;
        last = last.next;
    }
    //出队列，从链表的头开始出
    public int poll(){
        if (head == null){
            return -1;
        }
        int val = 0;
        if (head.next == null){
            val = head.val;
            head = null;
            last = null;
            return val;
        }
        val = head.val;
        head = head.next;
        return val;
    }

}
